#ifndef LOGDATA_H
#define LOGDATA_H

#include<plib.h>
#include"plot.h"

/* initial memory allocation */
#define METHODS 4
#define SAMPLES 200
#define COARSE  10
#define IDS 100

/* .time.log data */
#define TIME_COARSENING 0
#define TIME_UNCOARSENING 1
#define TIME_EXECTIME 2
#define TIME_INITIAL 3
#define TIME_TOTAL 4

/* .log data */
#define LOG_CUTEDGE 0
#define LOG_TOTCOMMCOST 1
#define LOG_MAXWEIGHT 2
#define LOG_CUTEDGEBYTOTCOMMCOST 3
#define LOG_IMBALANCE 4
#define LOG_MAXEXECTIME 5
#define LOG_TOTEXECTIME 6
#define LOG_IMBEXECTIME 7

/* .bet.log data */
#define BET_CUTEDGE 0
#define BET_TOTCOMMCOST 1
#define BET_MAXWEIGHT 2
#define BET_CUTEDGEBYTOTCOMMCOST 3
#define BET_IMBALANCE 4
#define BET_MAXEXECTIME_025 5
#define BET_MAXEXECTIME_05 6
#define BET_MAXEXECTIME_1 7
#define BET_MAXEXECTIME_2 8

/* search value */
/* stat pos */
#define LD_AVG 0
#define LD_STDDEV 1
#define LD_MIN 2
#define LD_MAX 3

/* grouping */
#define BY_MATCHING 0
#define BY_COARSENING 1

typedef struct logFinfo {
  char* base;
  char* coords;
  char* F_graph;
  char* F_grid;
}logFinfo;

typedef struct logF {
  int max_d;           /* max possible data fields */
  int max_m;           /* max          methods */
  int max_s;           /* max          samples */
  int max_c;           /* max          coarsening files */

  int *s;              /* number of samples for each method */
  int d;               /* number of data */

  double ***data;      /* data[method][field][sample] */
  double ***s_data;    /* statistics on data s_data[field][method][0-1] 
			  0 for average
			  1 for standard deviation 
			  2 min
			  3 max
		       */
  int **matching;      /* matching[method][sample] id of matching file is 
			  using serialize files */
  int **id;            /* id[method][sample] id of result file */
  
  double **sum;        /* for stat calculations sum[method][field] */
  
  int m;               /* number of methods */
  char **methods;      /* methods names methods[method]*/

  int c;               /* number of matching files */
  char **coarse;       /* matching file names */
}logF;

logF *LD_readTime(FILE *,ctrl*);
logF *LD_readLog(FILE *,ctrl*);
logF *LD_readBetLog(FILE *,ctrl*);
void LD_free(logF*);

double** LD_getData(logF *log,int x, int *methods,int nbmethods,int group, int* nbdat);
plot *LD_getPlotXY(logF*,int x,int y,int *methods,int nbmethods,int group,char *xlabel,char *ylabel, char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYZ(logF *log,int x,int y,int z,int *methods,int nbmethods,int group,char *xlabel,char *ylabel, char* zlabel, char *title, int border, int grid, int key, int xtics, int ytics);

double** LD_getDataMatch(logF*,double *x, int *methods,int nbmethods,int group, int* nbdat);
plot *LD_getPlotXYmatchX(logF*,int y,double* x,int *methods,int nbmethods,int group,char *xlabel,char *ylabel, char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYZmatchX(logF *log,int y,int z,double* x,int *methods,int nbmethods,int group,char *xlabel,char *ylabel,char *zlabel,char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYZmatchXY(logF *log,int z,double* x,double* y,int *methods,int nbmethods,int group,char *xlabel,char *ylabel,char *zlabel,char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYiniX(logF *log,int y,double** x,int *methods,int nbmethods,int group,char *xlabel,char *ylabel, char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYZiniX(logF *log,int y,int z,double** x,int *methods,int nbmethods,int group,char *xlabel,char *ylabel,char *zlabel,char *title, int border, int grid, int key, int xtics, int ytics);
plot *LD_getPlotXYZiniXY(logF *log,int z,double** x,double** y,int *methods,int nbmethods,int group,char *xlabel,char *ylabel,char *zlabel,char *title, int border, int grid, int key, int xtics, int ytics);


int LD_logBestByMethod(logF *l,int f,int s,char*** match,double **val,int** id);
char* LD_logBestMatching(logF *l,int f,int s,double *val,int* id);
int* LD_getMatchingIds(logF* log,int coarse);

logFinfo* LD_readInfo(int argc,char* argv[]);
void LD_freeInfo(logFinfo* info);
#endif
